package com.homework.controller;/**
 * @author： li
 * @date： 2021-05-18 18:21
 * @version 1.0
 */

import javax.servlet.*;
import java.io.IOException;
import java.sql.SQLException;

import com.homework.bin.user;
import com.homework.service.userservice;
/**
 * @author： Administrator
 * @date： 2021-05-18 18:21
 * @version 1.0
 */
public class loginServlet implements Servlet {
    @Override
    public void init(ServletConfig config) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
                          String username=req.getParameter("username");
                          String password=req.getParameter("password");
                          user us=new user();
                          us.setUsername(username);
                          us.setPassword(password);
                          userservice userservice=new userservice();
                          int i=0;
        try {
            i=userservice.login(us);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(i==1) {
                              req.getRequestDispatcher("/successlogin.jsp").forward(req, res);
                          }else {
                              req.getRequestDispatcher("/faillogin.html").forward(req,res);
                          }
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
